package no.ntnu.fp.gui;

import javax.swing.JList;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import no.ntnu.fp.model.Message;
import no.ntnu.fp.model.Person;
import no.ntnu.fp.model.Appointment.RSVP;

import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.border.EtchedBorder;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;

public class MessagePanel extends JPanel {

	/**
	 * Create the panel.
	 * @param message 
	 */
	private Message message;
	private JList messages;
	public MessagePanel(Message message) {
		this.message = message;
		setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		setLayout(new MigLayout("", "[][][][][]", "[][][][][]"));
		
//		JLabel lblTitle = new JLabel(message.getAppointment().getTitle());
		JLabel lblTitle = new JLabel("Bjarne mote");
		lblTitle.setFont(new Font("Dialog", Font.BOLD, 12));
		add(lblTitle, "cell 1 1");
		
		JLabel lblDescription = new JLabel(message.getMessageType().toString());
		add(lblDescription, "cell 1 2");
		
		JButton btnAccept = new JButton("Godta");
		btnAccept.setBackground(Color.GREEN);
		add(btnAccept, "cell 1 4");
		btnAccept.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				acceptInvite(true);
			}
		});
		
		JButton buttonCancel = new JButton("Avsl\u00E5");
		buttonCancel.setBackground(Color.RED);
		add(buttonCancel, "cell 2 4");
		buttonCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				acceptInvite(false);
			}
		});
		this.setBackground(Color.WHITE);

	}
	/*
	 * creates new boxes for each message.
	 */
	public List<MessagePanel> getMessagePanels(){
		List<Message> messages = new ArrayList<Message>();
		List<MessagePanel> panels = new ArrayList<MessagePanel>();
		
		messages = Person.getCurrentUser().getMyMessages();
		
		for(Message m : messages){
			panels.add(new MessagePanel(m));
		}	
		return panels;
	}
	
	public void acceptInvite(boolean accepted) {
		/*
		if (accepted) {
			message.getAppointment().setRSVP(RSVP.ATTENDING, Person.getCurrentUser());
		}
		else {
			message.getAppointment().setRSVP(RSVP.NOT_ATTENDING, Person.getCurrentUser());
		}*/
	}
}
